package com.lkm.market2_0.m.steelyardstatus;

import com.google.gson.annotations.SerializedName;
import com.lkm.javatool.BitHelp;
import com.lkm.javatool.NumberHelp;
import com.lkm.market2_0.m_imple.steelyardserver.server.Config;




public class StatusInfo {


    public final static int Status_isException=1<<1;




    @SerializedName("szStatus")
    private int szStatus = 0;

    @SerializedName("vl")
    private float voltage;
    @SerializedName("mac")
    private String steelyardMac;
    @SerializedName("status")
    private int status;
    @SerializedName("lt")
    private long lastActionTime;

    @SerializedName("v")
    private String version;

    @SerializedName("nn")
    private String steelyardNumno;

    
    private transient boolean isDisConnect = false;


    public void addFlag(int statusFlag){
        status=BitHelp.addFlagBit(status,statusFlag);
    }
    public void removeFlag(int statusFlag){
        status=BitHelp.removeFlagBit(status,statusFlag);
    }

    public void setLastActionTime(long lastActionTime) {
        this.lastActionTime = lastActionTime;
    }

    public void setIsException(boolean isException) {
        if(isException) {
            addFlag(Status_isException);
        }else {
            removeFlag(Status_isException);
        }
    }


    

    public boolean isOnline() {
        if(isDisConnect){
            return false;
        }
        return System.currentTimeMillis()-lastActionTime <= Config.steelyardActionOutTime;
    }
    public boolean isException() {
        return BitHelp.hasFlagBit(status,Status_isException);
    }

    public String getSteelyardMac() {
        return steelyardMac;
    }

    public void setSteelyardMac(String steelyardMac) {
        this.steelyardMac = steelyardMac;
    }

    public String getVersion() {
        return version;
    }
    public int getVersionInt() {
        return NumberHelp.toInt(version,0);
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public long getLastActionTime() {
        return lastActionTime;
    }

    public String getNumno() {
        return steelyardNumno;
    }

    public void setNumno(String steelyardNumno) {
        this.steelyardNumno = steelyardNumno;
    }

    public synchronized boolean isDisConnect() {
        return isDisConnect;
    }

    public synchronized void  setDisConnect(boolean disConnect) {
        isDisConnect = disConnect;
    }

    public float getVoltage() {
        return voltage;
    }

    public void setVoltage(float voltage) {
        this.voltage = voltage;
    }

    public int getSzStatus() {
        return szStatus;
    }

    public void setSzStatus(int szStatus) {
        this.szStatus = szStatus;
    }
}
